package com.androidx.p013lv.mine.novel.fragment;

import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.GridLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.novel.AttentionNovelAnchorBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.databinding.FragmentMineAttentionNovelBinding;
import com.androidx.p013lv.mine.novel.adpter.MineAttentionNovelAdapter;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

/* renamed from: com.androidx.lv.mine.novel.fragment.MineAttentionNovelFragment */
public class MineAttentionNovelFragment extends LazyFragment<FragmentMineAttentionNovelBinding> implements ItemClickListener, OnRefreshLoadMoreListener {
    MineAttentionNovelAdapter adapter;
    int lastId = 0;

    public static MineAttentionNovelFragment newInstance() {
        Bundle bundle = new Bundle();
        bundle.putString("", "");
        MineAttentionNovelFragment mineAttentionNovelFragment = new MineAttentionNovelFragment();
        mineAttentionNovelFragment.setArguments(bundle);
        return mineAttentionNovelFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1207R.C1212layout.fragment_mine_attention_novel;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ((FragmentMineAttentionNovelBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentMineAttentionNovelBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentMineAttentionNovelBinding) this.binding).recycler.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        this.adapter = new MineAttentionNovelAdapter();
        ((FragmentMineAttentionNovelBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(this);
        ((FragmentMineAttentionNovelBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.novel.fragment.MineAttentionNovelFragment.View$OnClickListenerC13751 */

            public void onClick(View view) {
                MineAttentionNovelFragment.this.lastId = 0;
                MineAttentionNovelFragment.this.getInfo();
            }
        });
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void onFirstUserVisible() {
        super.onFirstUserVisible();
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        String str;
        if (this.lastId == 0) {
            MineAttentionNovelAdapter mineAttentionNovelAdapter = this.adapter;
            if (!(mineAttentionNovelAdapter == null || mineAttentionNovelAdapter.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((FragmentMineAttentionNovelBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((FragmentMineAttentionNovelBinding) this.binding).statusLayout.showLoading();
        }
        if (this.lastId == 0) {
            str = UrlManager.getInsatance().fictionAttentionAnchorList("", 30);
        } else {
            str = UrlManager.getInsatance().fictionAttentionAnchorList(String.valueOf(this.lastId), 30);
        }
        HttpUtils.getInsatance().get(str, new HttpCallback<BaseRes<AttentionNovelAnchorBean>>("fictionAttentionAnchorList") {
            /* class com.androidx.p013lv.mine.novel.fragment.MineAttentionNovelFragment.C13762 */

            public void onLvSuccess(BaseRes<AttentionNovelAnchorBean> baseRes) {
                ((FragmentMineAttentionNovelBinding) MineAttentionNovelFragment.this.binding).statusLayout.hideLoading();
                ((FragmentMineAttentionNovelBinding) MineAttentionNovelFragment.this.binding).refresh.finishRefresh();
                ((FragmentMineAttentionNovelBinding) MineAttentionNovelFragment.this.binding).refresh.finishLoadMore();
                if (baseRes.getCode() == 200) {
                    if (baseRes.getData() != null && baseRes.getData().getData() != null && baseRes.getData().getData().size() > 0) {
                        MineAttentionNovelFragment.this.adapter.setDomain(baseRes.getData().getDomain());
                        if (MineAttentionNovelFragment.this.lastId == 0) {
                            MineAttentionNovelFragment.this.adapter.setData(baseRes.getData().getData());
                            ((FragmentMineAttentionNovelBinding) MineAttentionNovelFragment.this.binding).refresh.resetNoMoreData();
                            return;
                        }
                        MineAttentionNovelFragment.this.adapter.setDatasInEnd(baseRes.getData().getData());
                    } else if (MineAttentionNovelFragment.this.lastId == 0) {
                        ((FragmentMineAttentionNovelBinding) MineAttentionNovelFragment.this.binding).statusLayout.showEmpty();
                    } else {
                        ((FragmentMineAttentionNovelBinding) MineAttentionNovelFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                    }
                } else if (MineAttentionNovelFragment.this.lastId == 0) {
                    ((FragmentMineAttentionNovelBinding) MineAttentionNovelFragment.this.binding).statusLayout.showError();
                } else {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            }
        });
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!isOnClick()) {
            ARouter.getInstance().build(Constance.AUDIO_ANCHOR_DETAILS_ACTIVITY).withInt("anchorId", ((AttentionNovelAnchorBean.AttentionNovelAnchorBeanData) this.adapter.getDataInPosition(i)).getAnchorId()).navigation();
        }
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        AttentionNovelAnchorBean.AttentionNovelAnchorBeanData attentionNovelAnchorBeanData = (AttentionNovelAnchorBean.AttentionNovelAnchorBeanData) this.adapter.getLastDataInPosition();
        if (attentionNovelAnchorBeanData == null) {
            ((FragmentMineAttentionNovelBinding) this.binding).refresh.finishLoadMore();
            ((FragmentMineAttentionNovelBinding) this.binding).refresh.finishLoadMoreWithNoMoreData();
            return;
        }
        this.lastId = attentionNovelAnchorBeanData.getSortNum();
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.lastId = 0;
        getInfo();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag("fictionAttentionAnchorList");
    }
}
